package com.wwc.common.interceptor;

import cn.hutool.core.util.RandomUtil;
import jakarta.annotation.Nonnull;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.slf4j.MDC;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

/**
 * 日志拦截器
 */
@Component
public class LogInterceptor implements HandlerInterceptor{
	@Override
	public boolean preHandle(@Nonnull HttpServletRequest request, @Nonnull HttpServletResponse response, @Nonnull Object handler){
		// 增加日志流水号
		MDC.put("LOG_ID", System.currentTimeMillis() + RandomUtil.randomString(3));
		return true;
	}
}
